Memory utilization analysis

ABSTRACT

An application records memory allocations and releases as they occur over time, and an analysis system presents characteristic memory utilization patterns to a user for review and analysis. A variety of sampling techniques are used to minimize the impact of this memory utilization monitoring on the performance of the application, and the analysis system is configured to estimate the overall memory utilization based on these samples. Because these samples of the memory allocations are taken continuously as the application is running, the analysis system can provide visualizations of the memory utilization patterns that allow a user to easily recognize anomalous behavior. The analysis system includes an interactive interface that allows the user to trace the cause of the presented memory utilization patterns, and provides statistics regarding memory allocation and release to guide the user in this analysis.

This application claims the benefit of U.S. Provisional PatentApplication 61/152,462, filed 13 Feb. 2009.

BACKGROUND AND SUMMARY OF THE INVENTION

This invention relates to the field of application development andanalysis, and in particular to a method and system that analyzes anapplication's use of memory, to identify memory leaks and their causes.

The increasing level of complexity and sophistication of applicationprograms has resulted in a significant increase in the amount of memorybeing used in such applications. Even though the cost of memory hassignificantly decreased over time, allowing for systems with substantialamounts of memory, the amount of memory available still remains a finitequantity.

If an application consumes an inordinate amount of memory, it willgenerally result in poor performance, and may result in failure of theapplication, and in some cases, a system failure. If the application isused for commercial transactions, such as operating a vendor's website,such poor performance and/or unreliable performance can result in theloss of sales, and in many cases, the loss of repeat customers. If theapplication is used for managing a business, such as an accounting orinventory application, poor or unreliable performance will result in aloss of productivity, and other problems.

A primary cause of excessive memory utilization is the presence of“memory leaks” within an application. As an application is run, it willtypically request allocations of memory as required for each task, thenrelease the memory for subsequent allocation to other tasks as each taskis completed. The release of memory may be direct or indirect. Insystems that use direct release, the designer explicitly de-allocatesthe memory when it is no longer required. If the user does notexplicitly de-allocate memory that is no longer required, that memory isnot made available for subsequent allocations.

In systems that use indirect release, the user releases memory bydecoupling the links/references to the items that are no longer beingused, and the system periodically performs ‘garbage collection’ toperform the de-allocation that identifies the memory as being availablefor subsequent reallocation. For example, terminating a subroutine thathad allocated memory for ‘local’ variables that are only used within thesubroutine will decouple the links to this memory, because these localvariables are no longer within the current scope of the program. Thenext time the garbage collector is run, it will determine all of the‘reachable’ objects (objects within the current scope of the program),and will de-allocate/release/free any memory that is not allocated to areachable object. Although garbage collectors alleviate the task ofexplicitly releasing memory when it is no longer required, they are notfool-proof, particularly if the creator of the application is carelesswith regard to controlling the scope of variables.

If the release of memory is not properly performed, the amount of memoryavailable for subsequent allocation will decrease; this loss ofallocatable/available/free memory is termed a memory leak. If a memoryleak continues over time, the amount of allocatable memory will decreaseto a point that a substantial amount of time will be consumed by thesystem as it tries to satisfy each subsequent allocation request withless and less available memory; eventually, the amount of allocatablememory will decrease to a point at which the application cannotcontinue, for lack of available memory, even though the memory that wasnot properly released is not being used.

In prior decades, most systems and applications were used sporadically,being turned on and off as required; as such, applications with memoryleaks would often be terminated before they introduced a noticeabledegradation in system performance. In today's “24-7” environment,however, in which applications are rarely turned off, even a “slow leak”in memory will eventually degrade system performance.

If applications are not sufficiently protected from each other withregard to memory allocation, a memory leak in one application will havethe effect of slowing down and eventually crashing other applications aswell. This ‘side-effect’ of an application's memory leak often makes itdifficult to determine which application is responsible for thedegradation in system performance, particularly in environments that donot allow for applications to be purposely shut down to perform properfault isolation tasks.

Conventional memory utilization analyzers take ‘snapshots’ of anapplication's use of memory over time, then compare snapshots toidentify growth patterns. For example, in “Memory Analysis BestPractices Within Eclipse”, a white paper by Steven Haines, published byQUEST SOFTWARE®, June 2008, the author instructs: “[t]ake a snapshot ofthe heap before your code runs[; t]ake a snapshot of the heap after yourcode runs[; and . . . t]he best strategy is to compute the differencebetween the “before” heap and the “after” heap, and then verify that newobjects are expected to be in the heap. If they're not, then you haveidentified a memory leak and can resolve it!” (“Memory Analysis BestPractices Within Eclipse”, page 7, lines 3-15; the heap is a list of allobjects to which memory is currently allocated.) A variety of analysistools are available for presenting a visualization of the contents ofthe heap, including a ‘dominator tree’ representation that illustratesthe hierarchical dependencies among the objects in the heap, detailedfurther below.

The author of the aforementioned white paper identifies the shortcomingsof the conventional ‘snapshot’ approach to memory utilization analysis:“However, keep in mind that only you, as the developer of the code, canproperly understand these ‘lingering objects’ in the context of yourapplication and determine whether there is truly a memory leak” (“MemoryAnalysis Best Practices Within Eclipse”, page 7, lines 27-29). That is,merely comparing a list of before-and-after active objects does not, perse, identify a memory leak. Additionally, if the code segment beinganalyzed is lengthy, with numerous functions and subroutines, it isgenerally very difficult to identify where the memory leaks are beingcreated, without searching through the code for each instance that eachsuspect object is likely to have been instantiated in memory.

It would be advantageous to be able to monitor the memory utilization ofan application over time, to clearly identify memory leaks or otheranomalies. It would also be advantageous to be able to perform thismonitoring of memory utilization in a production environment withoutsignificantly interfering with the operation of the application. Itwould also be advantageous to be able to identify the cause of memoryleaks or other anomalies within the application.

These advantages, and others, can be realized by augmenting anapplication to record memory allocations and releases as they occur overtime, and providing an analysis system that presents characteristicmemory utilization patterns to a user for review and analysis. A varietyof sampling techniques are used to minimize the impact of this memoryutilization monitoring on the performance of the application, and theanalysis system is configured to estimate the overall memory utilizationbased on these samples. Because these samples of the memory allocationsare taken continuously as the application is running, the analysissystem can provide visualizations of the memory utilization patternsthat allow a user to easily recognize anomalous behavior. The analysissystem includes an interactive interface that allows the user to tracethe cause of the presented memory utilization patterns, and providesstatistics regarding memory allocation and release to guide the user inthis analysis. In a preferred embodiment, the monitoring of memoryutilization also includes conventional heap dumps, and the interactiveinterface is configured to couple the memory utilization patterns withthe conventional presentation of such heap dumps, to facilitateefficient resolution of memory leaks and other anomalies.

BRIEF DESCRIPTION OF THE DRAWINGS

The invention is explained in further detail, and by way of example,with reference to the accompanying drawings wherein:

FIGS. 1A-1C illustrate example flow diagrams for augmenting anapplication in accordance with aspects of this invention.

FIG. 2 illustrates an example flow diagram for analyzing and presentingmemory utilization trends in accordance with aspects of this invention.

FIGS. 3A-3C illustrate example displays of memory utilization trends inaccordance with aspects of this invention.

FIGS. 4A-4B illustrate example displays of additional details related tothe memory utilization trends in accordance with aspects of thisinvention.

FIG. 5 illustrates an example block diagram of a memory utilizationanalysis system in accordance with aspects of this invention.

Throughout the drawings, the same reference numerals indicate similar orcorresponding features or functions. The drawings are included forillustrative purposes and are not intended to limit the scope of theinvention.

DETAILED DESCRIPTION

In the following description, for purposes of explanation rather thanlimitation, specific details are set forth such as the particulararchitecture, interfaces, techniques, etc., in order to provide athorough understanding of the concepts of the invention. However, itwill be apparent to those skilled in the art that the present inventionmay be practiced in other embodiments, which depart from these specificdetails. In like manner, the text of this description is directed to theexample embodiments as illustrated in the Figures, and is not intendedto limit the claimed invention beyond the limits expressly included inthe claims. For purposes of simplicity and clarity, detaileddescriptions of well-known devices, circuits, and methods are omitted soas not to obscure the description of the present invention withunnecessary detail.

This invention is presented using the paradigm of a system thatautomatically performs regular garbage collections. These garbagecollections may be performed periodically, or on an as-needed basis,when the amount of available memory drops below some particularcriterion, or as a combination of both. One of skill in the art willrecognize that the principles presented herein are also applicable tosystems in which the application is programmed to perform such garbagecollections, or to explicitly release memory allocations, or acombination of both.

Providing an efficient and effective memory utilization analysis methodor system involves satisfying a variety of objectives and constraints.Ideally, if each memory allocation and release were recorded, with anindication of the segment of code that was responsible for eachallocation, an analysis system could process this information toidentify objects that are repeatedly created and not released, as wellas identifying which segment of the code needs to be modified to correcteach such memory leak. However, the amount of storage and processingtime required to record such information for each and every memoryallocation and release renders this approach impractical for any but thesimplest of applications.

Additionally, even if such information could be recorded, the number ofobjects that are allocated memory in a non-trivial application caneasily amount to thousands, or hundreds of thousands, of objects eachminute. If the application's memory leaks are limited to a few objectsthat are often allocated, these object will stand out from the otherobjects and be identifiable to the user. If, on the other hand, theapplication's memory leaks are more pervasive, as is typical,distinguishing particular objects that are not being effectivelyreleased becomes increasingly difficult. Because the life-span of eachobject in an application can vary from a mere instance to the entireduration of the application, it is difficult to determine whether memoryfor any particular object remains allocated longer than it should.Therefore, automated means of identifying objects that are the result ofportions of code causing a memory leak is difficult, if not impossible.That is, even with total information available regarding allocations andreleases, an object-based analysis suffers the same limitations as theaforementioned before-and-after heap analyses of requiring someoneintimately familiar with the application to identify objects that shouldhave been released sooner.

The inventors have recognized that recording the allocation and releaseof memory for individual objects, and the cause of such allocations,provides the best information for tracing the cause of memory leaks, butthe practical limitations of collecting such information, automating theanalysis, and presenting meaningful information to the user require theuse of alternative techniques, based on characteristic memoryutilization patterns, and in particular memory utilization patternsassociated with memory leaks.

In particular, the inventors have recognized that a problematic memoryleak will generally exhibit a somewhat regular behavior as theapplication is run. That is, if a memory leak occurs, but does notre-occur, its effects will not be cumulative, and will not result in acontinuing degradation in the performance of the application;accordingly, such a memory leak would not generally be consideredproblematic.

The inventors have also recognized that problematic memory leaks aregenerally characteristic of the techniques used to develop theapplication. That is, if a problematic memory leak exists, it is notlikely to be isolated to a single object; rather, the problem is likelyto be repeated each time memory is allocated to a similar object.Accordingly, a sampling of allocations and releases will be sufficientto identify memory utilization patterns, without requiring the recordingof each and every allocation and release.

Therefore, in a preferred embodiment of this invention, selectallocations are recorded, including an identification of the objectbeing instantiated, as well as the section of code in the applicationthat initiated this instantiation. Additionally, the release of each ofthese sampled allocations are recorded. In this manner, if memory leaksor other memory utilization anomalies are present in the application,they are likely to be detected, based on when or if the sampledallocation is released. Further, because the sampling includes recordingan identification of the code segment that caused the allocation, it islikely that this identification will be representative of the codesegments that are responsible for the causes of allocations throughoutthe sampling period. That is, by recording samples of allocations andreleases, the overhead associated with recording this information issubstantially reduced, yet the information that can be gleaned from thissampled information will generally be sufficient to identify memoryleaks, and their causes.

Additionally, the life spans of similar objects can be expected to besimilar; or, alternatively stated, the expected life span of an objectcan be expected to be dependent upon its type, or class. For example, ina payroll application, the life span of an employee's record within theapplication is likely to be similar to the life span of any otheremployee's record. Alternatively stated, properly allocated and releasedobjects of a given type/class can be expected to be significantlydifferent from the life span of the same objects that are not properlyreleased. Accordingly, an analysis and presentation of memoryutilization patterns based on the type or class of objects can beexpected to provide a more meaningful result to a user than resultsbased on particular objects.

In a preferred embodiment of this invention, even though the allocationsare recorded on an object-by-object basis, the analysis and presentationof memory utilization patterns are based on the type or class of objectsbeing allocated and released. However, because the details of thesampled allocations and releases are available, the user is provided theopportunity to investigate the specific causes of any memory utilizationpattern that appears to indicate a memory link or other memoryutilization anomalies.

Recording Allocations and Releases

FIGS. 1A-1C illustrate example flow diagrams for augmenting anapplication in accordance with aspects of this invention. In a dynamicmemory allocation process, objects are created (instantiated in memory)as needed, when they first become within the scope of the application(become ‘reachable’), then disposed (memory released) when no longerwithin the scope of the application ('unreachable'). In accordance withan aspect of this invention, some of these instantiations and subsequentreleases are recorded for subsequent analysis.

FIG. 1A illustrates the augmentation of a conventional memory allocationprocess that is typically called as each object is instantiated in anapplication. At 110, the required amount of memory is allocated to theobject, in the conventional manner.

At 115, the augmented process determines whether this allocation shouldbe sampled for recording. Any of a number of techniques can be used forthis sampling, as detailed further below. In a straightforwardembodiment of this invention, every Nth allocation is sampled, where Ncan be any number, depending on the degree of precision desired,balanced against the overhead introduced by this sampling. In a typicalembodiment, N is at least one hundred, so that the performance of theapplication is not significantly affected by this sampling overhead, andpreferably less than a thousand, to assure that even slight memory leaksare represented in the sampled recordings.

If the allocation is selected for recording, an identification of theobject is recorded as well as the time of the allocation and anidentification of the location in the application from which theinstantiation was initiated, at 120. This location information istypically obtained from the last entry in the ‘call stack’ of theapplication; in a preferred embodiment, the entire call stack isrecorded, to identify the path that lead to this allocation. As detailedfurther below, the class of the object is also preferably recorded, tofacilitate the presentation of memory utilization trends and statisticsbased on object class. Other information may also be recorded, such asthe size of the object, although this information can be determined fromthe object class.

At 125, the object ID is also recorded in a list of objects currentlybeing monitored, to facilitate a rapid identification of monitoredobjects in the augmented release process of FIG. 1B.

FIG. 1B illustrates the augmentation of a conventional deletion of anobject from active memory, such as typically performed in a garbagecollection process. In a typical garbage collection process, eachreachable object in the currently allocated dynamic memory(conventionally termed the ‘heap’) is identified, so that the memorycurrently allocated to unreachable objects can be released forallocation to subsequently instantiated objects. To allow for efficientsubsequent allocation, the reachable objects in the heap are typicallyrelocated to form a contiguous block of memory. At 140, the memorycurrently allocated to each unreachable object is released in theconventional manner.

At 145, the augmented process determines whether the unreachable objectis included in the aforementioned list of monitored objects. If it is acurrently monitored object, its identifier and the time of release isrecorded, at 150, and its identifier is removed from the list ofcurrently monitored objects, at 155.

One of skill in the art will recognize that the particular form of therecorded information is irrelevant to the principles of this invention,and the reference herein to separate recordings and lists is presentedfor ease of understanding. It will be recognized that, for example, therelease time can merely be another field in the record of allocations,rather than maintaining a separate list of releases. In like manner, theidentification of currently monitored objects could be performed byidentifying each object in this combined allocation/release record thathas not yet been released. One of skill in the art will recognize,however, that maintaining separate lists for the particular functionsmay allow for more efficient processing.

With the augmented processes of FIGS. 1A and 1B, a sampling ofallocations and corresponding releases will be recorded as theapplication is run; and, because the sampling rate can be kept low, theimpact of this sampling will have a minimal affect on the performance ofthe application in an operating environment.

FIG. 1C illustrates an example flow diagram for reporting the records ofthe sampled allocations and releases, as well as other information thatwill facilitate the identification of memory utilization trends. Thisreporting is typically performed by writing the information to a filethat can subsequently be accessed by an analysis program. Theapplication is augmented to execute this process regularly, such asbased on a time since the last execution, based on the number ofcurrently recorded allocations, based on the occurrence of particularevents in the application, based on a user request, or combinations ofthese and other reporting parameters.

At 170, the recorded allocations and releases are reported, andcompleted records of objects (allocated and released memory) are removedfrom the records within the application. At 175, the current status ofthe heap is reported, using conventional techniques for obtaining asnapshot of the memory allocation, as discussed above. Other applicationstatus information may also be reported, at 180, such as a record of thetimes and duration of garbage collection, and so on.

Analysis and Display of Monitored Information

FIG. 2 illustrates an example flow diagram for analyzing and presentingmemory utilization trends in accordance with aspects of this invention.FIGS. 3A-3D illustrate example displays of these trends and otherstatistics provided by this example analysis and presentation process.

As noted above, in a preferred embodiment of this invention, theanalysis and presentation of information regarding memory utilizationpatterns is organized by object class. Presentation by object class willallow a user to quickly distinguish expected memory utilization andanomalous utilization, such as a memory leak. For example, in a typicalpayroll application, objects of class ‘employee record’ will be expectedto have limited individual duration between allocation and release, aseach employee is processed, and the number of employee records that arecurrently active/reachable during the application can be expected toremain fairly constant. Conversely, if the application is configured tocreate objects of class ‘paycheck record’ and then submit these objectsregularly to a printing process, the life span of each paycheck recordwill be dependent upon when the paycheck record was created. That is,the creation of a continuously increasing number of paycheck records isproper behavior, and the number of active/reachable paycheck records canbe expected to continually increase until they are offloaded to theprinting process.

At 210, the information reported from the augmented application isorganized by object class. Optionally, this grouping by class could havebeen performed by the application before the information was reported.However, performing this task in the analysis program reduces theimposed overhead at the augmented application.

At 220, memory utilization patterns are determined for each objectclass, or for each of the predominate object classes, or for each objectclass of interest to the user, or combinations of these and otherselection parameters.

Of particular note, because the actual allocations and releases arerecorded based on a sampling of the allocations, the characteristics ofthe memory utilization for any particular object class can beestimated/determined from these sampled allocations. In the example ofsampling every Nth allocation, if the number of sampled objects of aparticular class within a given period of time is k, the number ofallocations for this class can be expected to have been N*k during thisperiod. The accuracy of this estimate will be a function of thedistribution characteristics of the class over time, and moresophisticated statistical techniques, common in the art, may be appliedto refine this estimate. However, for the purposes of determininggeneral memory utilization trends, the degree of accuracy required isfairly low.

FIG. 3A illustrates an example presentation of allocation rates for aset of object classes, based on the recording of sampled allocations andreleases. At the table 310, the number of live objects 311 of each classat the end of the given time period is presented, as well as theallocation rate during this time period. This allocation rate can beeither an average over the time period, or an estimate of the rate atthe end of the time period based on the characteristics/trend of thesampled allocations over this time period.

If the user selects an object class 315 at the table 310, the detailsregarding the allocations and releases for this object class arepresented in graphic form 320, 325. In this example, at 320, the rate ofallocation of the selected object class 315 is displayed over time(approximately fifteen minutes), and, at 325, the number oflive/reachable objects in this class 315 is displayed for this same timeperiod. In this particular example, the sampling occurred atapproximately every 250 allocations, and each sampled allocation thatwas an object of this class 315 is estimated to have corresponded toabout 250 allocations of that class 315. During the example fifteenminutes, nearly a thousand of the sampled allocations were of this class315, with no releases, resulting in an estimated number oflive/reachable objects of this class 315 at the end of the period ofalmost 250,000, at 326.

Of particular note, these graphs 320, 325 are based on the sampledallocations and releases, and not on the conventional snapshots of theheap. In the fifteen minutes represented by these graphs, over 40,000allocations were recorded, or approximately fifty every second, allowingthese graphs to provide sub-second resolution. Because the overheadassociated with each recording is relatively slight, and the recordingrate is relatively low, the overhead introduced to the application isalso slight. Contrarily, if fifty conventional snapshots of the heapwere attempted every second, the application's performance would bedramatically affected, and the reported allocation rates and resultantnumber of live objects would likely be meaningless with regard to theapplication's true allocation rates when not burdened with numeroussnapshots every second. In this example, at the end of the fifteenminute interval, the heap contained over fifty million objects;reporting the contents of the heap, as is done in a conventionalsnapshot, would require reporting all of these fifty million objects. Ina conventional memory utilization analysis, snapshots are typicallytaken only at particular points in time identified by the developer ofthe application to isolate identified problems, or, as noted in theaforementioned “Memory Analysis Best Practices Within Eclipse”, at thebeginning and end of selected processes within the application.

FIG. 3B illustrates another example presentation of memory utilizationtrends over time. In this example, the amount of available memory (freeheap) is displayed over time based on the sampled allocations andreleases, at 330. As can be seen, in this example application, theamount of available memory is continually decreasing, which isindicative of a severe memory leak. Additionally, at 335, the amount oftime spent in garbage collection is illustrated, and as can be seen,this amount increases dramatically, at 337, as the amount of availablememory becomes very low.

At 340, the allocation rate in megabytes per second is illustrated,based on the sampled allocations of objects and their size. As can beseen, the allocation rate is not decreasing, indicating that unlesssomething changes, the application is likely to run out of availablememory in the next few minutes. In a preferred embodiment, a ‘health’index is given, at 345, which is intended to indicate the likelihood ofthe application being able to continue. This index ranges from 0 to 100,and in this example, the likelihood of the application being able tocontinue is estimated at less than one percent.

FIG. 3C illustrates another example presentation of memory utilizationtrends over time. In this example, the number of live/reachable objectsin each object class is displayed over time, at 350. In this example,three of the object classes 354, 355, 356 exhibit a relativelyconsistent number of live objects at any given point in time, whereasthe other three object classes 351, 352, 353 exhibit a continuallyincreasing number of live objects over time, which is characteristic ofa memory leak.

Alternatively, one or more of these object classes 351, 352, 353 couldbe records that are purposely created by the program, such as theaforementioned paycheck objects that are accumulated until they are sentto a printing process. By organizing and presenting the memoryutilization trends based on object class, the user can easilydistinguish between objects that are expected to consume more and morememory, and objects that are inadvertently consuming more and morememory (i.e. memory leaks).

Returning to FIG. 2, at 240, during the presentation of the memoryutilization trends, in addition to providing the user control of theparticular form of presentation, the user is provided the option ofquerying the system for additional details. Typically, this is providedby allowing the user to “drill down” for additional information byselecting a displayed object of interest, such as by ‘clicking’ on oneof the patterns 351-356, or the corresponding text item in the table360. Other forms of indicating a query for additional information arecommon in the art.

At 250, the more detailed information requested by the user ispresented, including, as detailed further below, an identification ofthe likely cause/source of memory leaks.

It is significant to note that there is often a hierarchicalrelationship among objects and object classes. For example, a higherlevel object class (parent) may be defined as containing lower levelobject classes (descendents), and these lower level object classes maybe defined as containing yet lower level object classes, and so on. Thishierarchical relationship has a significant impact on the allocation andrelease of memory. When a parent object is instantiated, all of itsdescendent objects (children, grandchildren, etc.) are instantiated.Correspondingly, when a parent object is released, all of its descendentobjects are released. In like manner, if a child object is released, itsgrandchildren, great-grandchildren, etc. objects are released.

As noted above, a variety of tools exist for presenting the hierarchicalrelationship among objects in a graphic tree form, commonly termed adominator tree, based on the information provided in a conventional heapdump. A dominator tree, however, is very detailed, in that it includeseach and every descendent object, and is not necessarily suitable forrepresenting memory utilization in a form that conveys trend informationto a user. Consistent with the aforementioned use of object classes toorganize information in a form that is visually meaningful to a user, ina preferred embodiment of this invention, a novel form of theconventional dominator tree is used.

In accordance with this aspect of the invention, the reported heap dumpfor the selected time period is processed to create a dominator tree,but instead of including each descendent object at each level of thehierarchy, objects of the same object class are grouped together to forma single node on the tree. This grouping may be, and preferably isperformed both laterally (siblings of the same class) and vertically(descendents of the same class). Each object class node also includes acount of the number of objects of the class being represented by thatnode. In this manner, it becomes readily apparent how many objects willbe released if that particular object class node is released.Optionally, the number of bytes of allocated memory that each objectclass node represents may also or alternatively be used to convey theeffect of the node's release.

The summarizing, or collapsing, of objects into an object class nodeprovides for an effective visualization of the tree, and is particularlyuseful in the detection of memory leaks, which often consist of largecollections of objects of a small set of classes. Preferably, therecorded allocation and release data associated with the descendentobject classes are accumulated at each level within the tree, therebyenabling the calculation of the total percentage of the memoryutilization associated with the descendants of each node in the tree. Ina preferred embodiment, the accumulated data is sorted so that childnodes that contribute the most to the growth in memory allocation appearas the first descendants at each level.

FIG. 4A illustrates an example presentation of a modified dominator treein accordance with this aspect of the invention. The first column 410identifies the object class nodes of the tree, each subsequentindentation of the class nodes indicating a lower hierarchical level ofthe tree.

For each displayed object class node, the total number of children 412and descendents 413 of that node is displayed, as well as the size 414of the object class, the total number of bytes of memory 415 allocatedto the object class, and the percentage of growth of memory utilization(heap growth) 416 associated with the object class, a growth of memoryutilization being indicative of a memory leak.

Of particular note, in this example, the first class node 420 beneaththe root node accounts for 100% of the growth in memory utilization.However, it is likely that a given number of objects of this objectclass are appropriate for the application, and the source of theinstantiation of these objects may not, per se, be the source of thememory leak. As illustrated in this example, the class node 420comprises two children class nodes 422 and 430. Class node 422 accountsfor 100% of the growth in memory utilization, while class node 430 doesnot cause any growth in memory utilization. That is, the cause of thegrowth associated with parent class node 420 is solely attributable tothe instantiation of objects of class 422, and therefore the cause ofthis growth should be further investigated. Proceeding in the samemanner, we see that the cause of the growth associated with objects ofclass 422 is solely caused by objects of class 424, and the cause ofthis growth is solely caused by the instantiation of objects of class426.

Having isolated the cause of growth in memory utilization to theinstantiation of objects of class 426, the user will subsequently reviewthe application code to find the error that is causing this memory leak.However, searching an application program for all of the instances wherean object of a particular class is instantiated is generally a tediousand burdensome task.

In accordance with another aspect of this invention, the systemidentifies where the instantiation of objects of this class occurswithin the application code, to facilitate identification of the causeof a memory leak. As noted above, when the instantiations are sampled,an identification of the object and its class are recorded, as well asthe call stack at the time of instantiation. The call stack indicatesthe sequence of calls to subroutines and functions within theapplication that lead to the instantiation, and thus provides a recordof where each sampled instantiation occurs. For ease of reference, theterm subroutine is used hereinafter to indicate a section of code thatis caused to be executed by a call to that subroutine.

FIG. 4B illustrates a graphic display of a composite of the call stacksthat lead to the instantiation of objects at or below the selected nodeof the denominator tree (in this example, object class 424 of FIG. 4A).

The call tree starts at the root 450 of the application, and therefore,100% of the instantiations of the as yet unreleased objects at or belowthe selected node occurs while the root is executing, as indicated. Fromthe root of the application, a subroutine 452 is executed, and everyinstantiation of these objects occurs while this subroutine 452 isexecuting. Similarly, all instantiations of the objects at or below theselected node occur while subroutines 454 and 456 are executing. Withinsubroutine 456, there are multiple locations at which the objects areinstantiated; approximately 41% of the instantiations occur withinsubroutine 460, 30% within subroutine 462, and 28% within subroutine464. Given this information, the user need only review three subroutines460, 462, and 464, to isolate the cause of the memory leak in theapplication.

As can be seen, by sampling the allocations and releases as they occurwhile the application is executing in an operational environment, thepresence of memory leaks can be easily identified, as well as thesource/cause of these leaks. By coupling these sampled allocations andreleases with the modified form of a dominator tree based on aconventional heap dump, which indicates the amount of memory and/or thegrowth of memory being consumed by each object class, the user of thesystem of this invention can focus on the most significantmemory-consuming objects to determine the cause of their memoryconsumption.

Sampling Techniques

In the examples above, the sampling of allocations is a straightforwardsampling of “every Nth allocation”. However, other sampling techniquesmay be used, each with particular advantages.

If, for example, a developer has made a modification to an application,the sampling could be restricted to the particular object classes thatare instantiated by the modification, thereby reducing the monitoringoverhead, and simplifying the analysis task.

In like manner, given that a leak of larger objects will have moreimpact on utilization than a leak of small objects, the sampling ratecould be size dependent, such as sampling medium sized objects at halfthe rate of larger objects, and small objects at a quarter of the rate.

As an extension to the size dependent sampling, the sampling can berestricted to objects above a given size threshold. Such an approach maybe particularly effective when an application is first being monitoredand analyzed. After all gross leaks are identified and cured, thethreshold can be reduced or eliminated.

The sampling may also be dependent upon the rate at which objects of agiven class are instantiated. That is, if an initial sampling indicatesthat objects of a particular object class are frequently instantiated,the sampling rate for that object class can be increased. Again, such asampling technique may be particularly effective when the application isfirst being monitored and analyzed. Alternatively, or additionally,after any gross leaks are identified and cured, the dynamic samplingrate adjustment can be canceled or reversed. That is, after theinstantiations of frequently instantiated objects are verified as notcausing memory leaks, they need not be sampled as frequently, and thesampling of the less frequently instantiated objects can be increased.

In like manner, the sampling may also be dependent on the age of theobjects of a given class. That is, if objects of a given class are foundto remain un-released for a long period of time, the sampling rate forthese objects may be increased, whereas if objects of another class arefound to be relatively short-lived, they need not be sampled as often.

In each of these sampling schemes, the analysis process should be awareof the particular sampling rules, so that the appropriate predictionscan be made regarding the actual allocations and releases. Any number oftechniques may be employed to assure that the analysis process isconsistent with the monitoring process, the most straightforward beingthe inclusion of the current sampling rules with the reportedinformation (FIG. 1C). In such an approach, the modification of thesampling rules, if any, would occur at each reporting period.Alternatively, the time of each change to the sampling rule can berecorded and subsequently reported, thereby allowing multiple changeswithin each reporting period.

One of skill in the art will recognize, however, that the analysisprocess need only be consistent with the sampling of the monitoringprocess if the reported information must be an accurate estimate of theactual allocation and release rates. If, on the other hand, the purposeof the analysis is to identify memory leaks regardless of theirmagnitude, an accurate assessment as to how much memory is being lost isnot required. In like manner, because the conventional heap snapshotscan provide an indication of the magnitude and rate of memoryutilization, the association between the sampled objects and the actualallocation can be determined using this snapshot information.

FIG. 5 illustrates an example memory utilization analysis system inaccordance with this invention. The analysis system contains acombination of hardware and software, hardware being required to performtasks and functions as specified by the software. The system isconfigured to perform some or all of the functions described above.

In accordance with aspects of this invention, an application 510 isaugmented to monitor memory allocations and releases, and to recordthese allocations and releases 520 for subsequent processing by ananalysis system 570. Preferably, to minimize the overhead associatedwith this monitoring, the application 510 is configured to sample fewerthan all of the memory allocations.

One of skill in the art will recognize that the system upon which theapplication 510 is executed may alternatively be augmented to performthis monitoring function for any application that is run on the system.That is, the augmentation of the memory allocation process may beperformed by the application that is requesting the allocation(instantiating an object), or by the system that is responding to therequest for this allocation. One of skill in the art will also recognizethat some or all of the analysis system 570 may be included in thesystem that is executing the application 510.

The application 510 is also configured to report 530 these monitoredallocations and releases 520, as well as other information, such as aconventional snapshot 540 of the allocated memory (heap), and other data550.

The analysis system 570 includes a processor that is configured toreceive the information 530, 540, 550, from the augmented application510, and to determine therefrom memory utilization trends 560, asdetailed above. These utilization trends 560 are provided to a user viaa graphic user interface 580, with which the user is provided theopportunity to control the form of the presentation, as well ascontrolling the level of detail provided for the various analyses, asdetailed above. Of particular note, because the recorded memoryallocations 530 include a record of the call stack at the time of eachinstantiation, the cause of problems identified by the memoryutilization trends can be identified. Additionally, because thereporting includes a heap dump 540 from which the hierarchicaldependencies of objects, and the corresponding size of memory allocationto each object class, can be identified, the graphic user interface 580can provide an integrated view that facilitates the efficient resolutionof memory leaks and other anomalies.

The foregoing merely illustrates the principles of the invention. Itwill thus be appreciated that those skilled in the art will be able todevise various arrangements which, although not explicitly described orshown herein, embody the principles of the invention and are thus withinits spirit and scope. For example, although the analysis system ispresented herein as a system that is active only when a user seeks ananalysis, one of skill in the art will recognize that the analysissystem can be configured to continually receive reports from an activeapplication, and provide an alarm feature, wherein if an anomalousmemory growth exceeds a given threshold, a user is notified. These andother system configuration and optimization features will be evident toone of ordinary skill in the art in view of this disclosure, and areincluded within the scope of the following claims.

In interpreting these claims, it should be understood that:

a) the word “comprising” does not exclude the presence of other elementsor acts than those listed in a given claim;

b) the word “a” or “an” preceding an element does not exclude thepresence of a plurality of such elements;

c) any reference signs in the claims do not limit their scope;

d) several “means” may be represented by the same item or hardware orsoftware implemented structure or function;

e) each of the disclosed elements may be comprised of hardware portions(e.g., including discrete and integrated electronic circuitry), softwareportions (e.g., computer programming), and any combination thereof;

f) hardware portions may include a processor, and software portions maybe stored on a computer-readable medium, and may be configured to causethe processor to perform some or all of the functions of one or more ofthe disclosed elements;

g) hardware portions may be comprised of one or both of analog anddigital portions;

h) any of the disclosed devices or portions thereof may be combinedtogether or separated into further portions unless specifically statedotherwise;

i) no specific sequence of acts is intended to be required unlessspecifically indicated; and

j) the term “plurality of” an element includes two or more of theclaimed element, and does not imply any particular range of number ofelements; that is, a plurality of elements can be as few as twoelements, and can include an immeasurable number of elements.

1. A method comprising: monitoring memory allocations as they occur in asystem that is running an application, sampling the memory allocationsto record sampled allocations, the sampled allocations being fewer thanan entirety of the memory allocations, recording releases of the sampledallocations, communicating the sampled allocations and releases to ananalyzer, processing, by the analyzer, the records of sampledallocations and releases to produce one or more memory utilizationpatterns, and displaying the one or more memory utilization patterns ona display device.
 2. The method of claim 1, wherein the sampling isperformed in accordance with a sampling rule, and the processingincludes estimating memory utilization associated with the totality ofthe memory allocations based on the sampling rule.
 3. The method ofclaim 1, wherein the sampling is performed based on a number of memoryallocations since a prior sampling.
 4. The method of claim 1, whereinthe sampling is performed based on an object class corresponding to thememory allocation.
 5. The method of claim 4, wherein the sampling isperformed based on a frequency of memory allocations to the objectclass.
 6. The method of claim 4, wherein the sampling is performed basedon a size of the memory allocation.
 7. The method of claim 4, whereinthe sampling is performed based on a duration of time that objects ofthe object class remain allocated to memory.
 8. The method of claim 1,wherein the sampling is performed based on a frequency of memoryallocations.
 9. The method of claim 1, wherein the sampling is performedbased on a size of the memory allocation.
 10. The method of claim 1,wherein the sampling is performed based on a duration of time thatobjects remain allocated to memory.
 11. The method of claim 1, includingcommunicating a record of current memory allocation to the analyzer,processing the record of current memory allocation to provide avisualization of the current memory allocation, and displaying thevisualization on the display device.
 12. The method of claim 11, whereinthe records of sampled allocations include records of a call stack foreach sampled allocation, and the displaying of the visualization of thecurrent memory allocation includes a visualization of a composite of oneor more of the call stacks.
 13. The method of claim 1, wherein therecords of sampled allocations include records of a call stack for eachsampled allocation, and the displaying of the memory utilizationpatterns includes a visualization of a composite of one or more of thecall stacks.
 14. The method of claim 1, wherein the records of sampledallocations and releases includes a time of each allocation and release,and displaying the memory utilization patterns includes a visualizationof memory utilization over time.
 15. The method of claim 1, wherein therecords of sampled allocations includes an object class of eachallocation, and displaying the memory utilization patterns includes avisualization of memory utilization for one or more object classes. 16.A method comprising: recording a plurality of records of memoryallocations and releases for an application as they occur in a systemthat is running the application, communicating the records of memoryallocations and releases to an analyzer, processing, by the analyzer,the records of memory allocations and releases to produce one or morememory utilization patterns, and displaying the one or more memoryutilization patterns on a display device.
 17. The method of claim 16,including communicating a record of current memory allocation to theanalyzer, processing the record of current memory allocation to providea visualization of the current memory allocation, and displaying thevisualization on the display device.
 18. The method of claim 17, whereinthe records of memory allocations include records of a call stack foreach memory allocation, and the displaying of the visualization of thecurrent memory allocation includes a visualization of a composite of oneor more of the call stacks.
 19. The method of claim 16, wherein therecords of memory allocations include records of a call stack for eachmemory allocation, and the displaying of the memory utilization patternsincludes a visualization of a composite of one or more of the callstacks.
 20. The method of claim 16, wherein the records of memoryallocations and releases includes a time of each allocation and release,and displaying the memory utilization patterns includes a visualizationof memory utilization over time.
 21. The method of claim 20, wherein therecords of memory allocations includes an object class of eachallocation, and displaying the memory utilization patterns includes avisualization of memory utilization for one or more object classes. 22.The method of claim 16, wherein the records of memory allocationsincludes an object class of each allocation, and displaying the memoryutilization patterns includes a visualization of memory utilization forone or more object classes.
 23. The method of claim 16, wherein therecords of memory allocations and releases include a sampling of fewerthan all of the memory allocations that occur in the application.
 24. Anon-transient computer readable medium that includes an applicationprogram that, when executed by a processor, causes the processor to:record a plurality of records of memory allocations and releases as theyoccur when the application program is executed, provide the records ofmemory allocations and releases for use by an analyzer to determinememory utilization patterns, wherein each record of memory allocationsand releases includes an identification of the allocation, a time of theallocation, and an identification of a location in the applicationprogram associated with the allocation, and a time of the release. 25.The medium of claim 24, wherein the plurality of records of memoryallocations and releases correspond to a sampling of the memoryallocations and releases that includes fewer than an entirety of thememory allocations and releases.
 26. The medium of claim 25, wherein thesampling is performed based on at least one of: a size of the memoryallocation, a number of memory allocations since a prior sampling. afrequency of memory allocations, and a duration of time that objectsremain allocated to memory.
 27. The medium of claim 25, wherein thesampling is performed based on an object class corresponding to thememory allocation.
 28. The medium of claim 25, wherein the sampling isperformed based on at least one of: a frequency of memory allocations tothe object class, a duration of time that objects of the object classremain allocated to memory.
 29. The medium of claim 24, wherein therecords of memory allocations include records of a call stack for eachmemory allocation.
 30. The medium of claim 24, wherein the records ofmemory allocations include a time of each allocation and an object classof each allocation.
 31. The medium of claim 24, wherein the applicationprogram is configured to cause the processor to provide a record ofcurrent memory allocation to the analyzer.
 32. A non-transient computerreadable medium that includes an analysis program that, when executed bya processor, causes the processor to: access a plurality of records ofsampled memory allocations and releases corresponding to an execution ofan application program, the sampled memory allocations and releasesbeing fewer than an entirety of the memory allocations occurring duringthe execution of the application program, process the records of memoryallocations and releases to produce one or more memory utilizationpatterns, and display the one or more memory utilization patterns on adisplay device, wherein each record of memory allocations and releasesincludes an identification of the allocation, a time of the allocation,an identification of a location in the application program associatedwith the allocation, and a time of the release.
 33. The medium of claim32, wherein the sampled memory allocations are selected in accordancewith a sampling rule, and the analysis program causes the processor toestimate memory utilization associated with the entirety of the memoryallocations based on the sampling rule.
 34. The medium of claim 32,wherein the records of sampled allocations include records of a callstack for each sampled allocation, and the analysis program causes theprocessor to display a visualization of a composite of one or more ofthe call stacks.
 35. The medium of claim 32, wherein the records ofsampled allocations and releases includes a time of each allocation andrelease, and the analysis program causes the processor to display avisualization of memory utilization over time.
 36. The medium of claim32, wherein the records of sampled allocations includes an object classof each allocation, and the analysis program causes the processor todisplay a visualization of memory utilization for one or more objectclasses.
 37. The medium of claim 32, wherein the analysis program causesthe processor to receive a record of current memory allocation to theanalyzer and process the record of current memory allocation to providea visualization of the current memory allocation.
 38. An analysis systemcomprising: a processor, and an analysis program that is configured tocause the processor to: access a plurality of records of sampled memoryallocations and releases corresponding to an execution of an applicationprogram, the sampled memory allocations and releases being fewer than anentirety of the memory allocations occurring during the execution of theapplication program, process the records of memory allocations andreleases to produce one or more memory utilization patterns, and displaythe one or more memory utilization patterns on a display device, whereineach record of memory allocations and releases includes anidentification of the allocation, a time of the allocation, anidentification of a location in the application program associated withthe allocation, and a time of the release.
 39. The system of claim 38,wherein the sampled memory allocations are selected in accordance with asampling rule, and the analysis program causes the processor to estimatememory utilization associated with the entirety of the memoryallocations based on the sampling rule.
 40. The system of claim 38,wherein the records of sampled allocations include records of a callstack for each sampled allocation, and the analysis program causes theprocessor to display a visualization of a composite of one or more ofthe call stacks.
 41. The system of claim 38, wherein the records ofsampled allocations and releases includes a time of each allocation andrelease, and the analysis program causes the processor to display avisualization of memory utilization over time.
 42. The system of claim38, wherein the records of sampled allocations includes an object classof each allocation, and the analysis program causes the processor todisplay a visualization of memory utilization for one or more objectclasses.
 43. The system of claim 38, wherein the analysis program causesthe processor to receive a record of current memory allocation andprocess the record of current memory allocation to provide avisualization of the current memory allocation.
 44. The system of claim38, including the application program that is configured to produce therecords of sampled memory allocations and releases.
 45. The system ofclaim 44, wherein the application program is configure to record theplurality of records of memory allocations and releases as they occurwhen the application program is executed.
 46. The system of claim 45,wherein each record of memory allocations and releases includes anidentification of the allocation, a time of the allocation, and anidentification of a location in the application program associated withthe allocation, and a time of the release.
 47. The system of claim 44,wherein the application program is configured to provide the pluralityof sampled allocations based on at least one of: a size of the memoryallocation, a number of memory allocations since a prior sampling. afrequency of memory allocations, and a duration of time that objectsremain allocated to memory.
 48. The system of claim 44, wherein theapplication program is configured to provide the plurality of sampledallocations based on an object class corresponding to the memoryallocation.
 49. The system of claim 48, wherein the application programis configured to provide the plurality of sampled allocations based onat least one of: a frequency of memory allocations to the object class,a duration of time that objects of the object class remain allocated tomemory.
 50. The system of claim 44, wherein the application program isconfigured to provide a record of current memory allocation.